<?php
include './include/common.php';
$cityid=$_GET['id'];
if (!$cityid&&empty($_COOKIE['wcity']['id'])) { //第一次访问，没有地区和cookie
	include SYSTEM_ROOTPATH . '/include/ipcha.php'; //模版编译类
	$myobj = new ipLocation();
	$IP = $myobj->get_IP();
	$address = $myobj->getaddress($IP );
	$myobj = NULL;
	$address["area1"]=mb_convert_encoding($address["area1"],"UTF-8","GBK" );
	$wordCity = $db->select ( "select `id`,`name`,`pinyin`,`Ab` from " . $table_top . "area where property=1" );
	foreach ( $wordCity as $v ) {
		if (strstr( $address ['area1'],$v['Ab'])) {
			SetCookie ( "wcity[pinyin]", $v ['pinyin'], time () + 600, "/", $SCRIPT_HOST );
			SetCookie ( "wcity[id]", $v ['id'], time () + 600, "/", $SCRIPT_HOST );
			SetCookie ( "wcity[name]", $v ['Ab'], time () + 600, "/", $SCRIPT_HOST );
			$_COOKIE ['wcity']['pinyin']=$v ['pinyin'];
			$_COOKIE ['wcity']['id']=$v ['id'];
			$_COOKIE ['wcity']['name']=$v ['Ab'];
			break;
		}
	}
}
	if (!$_COOKIE ['wcity']['name']) {
			SetCookie ( "wcity[pinyin]", $v ['pinyin'], time () + 600, "/", $SCRIPT_HOST );
			SetCookie ( "wcity[id]", $v ['id'], time () + 600, "/", $SCRIPT_HOST );
			SetCookie ( "wcity[name]", $v ['name'], time () + 600, "/", $SCRIPT_HOST );
			$_COOKIE ['wcity']['pinyin']='shanghai';
			$_COOKIE ['wcity']['id']='310000';
			$_COOKIE ['wcity']['name']='上海';
			
		}
$cityid=$_GET['id']?$_GET['id']:$_COOKIE ['wcity']['id'];

$city=$db->getone("SELECT * FROM {$table_top}area WHERE `id`='{$cityid}'");
$nowdate=date("Y-m-d");
$Rs=$db->getone("SELECT * FROM {$table_top}weatherlog WHERE `AreaID`='{$cityid}' and `Update`='{$nowdate}'");
$Weather=str_replace ( "@", "\\", $Rs['Weather'] );
$Weather=json_decode($Weather,TRUE);
$rs=$db->getone("SELECT WeatherCode FROM {$table_top}weather WHERE `AreaID`='{$cityid}'");
$WeatherCode=$rs['WeatherCode'];
$shishi=$db->getone("select * from {$table_top}weatherinfo where `cityid`='{$WeatherCode}'");

$_GET['id']&&$city['Ab']='';

if($Weather[4][0]!=$Weather[10][0]){
$tq=$Weather[4][0]."转".$Weather[10][0];
}else{
$tq=$Weather[4][0];
}
$date_3=date("m").'月'.date("d",strtotime("+1 day")).'日';
$date_4=date("m").'月'.date("d",strtotime("+2 day")).'日';
$date_5=date("m").'月'.date("d",strtotime("+3 day")).'日';
$date_6=date("m").'月'.date("d",strtotime("+4 day")).'日';
$s20=<<<EOT
<div class="s1"><img src="{$Weather[3][0]}" width="20" height="20" />{$Weather[5][0]} ~ {$Weather[11][0]}℃<br>今天：{$Weather[4][0]}<br>{$Weather[6][0]}</div>
EOT;
$s21=<<<EOT
<div class="s1"><img src="{$Weather[3][1]}" width="20" height="20" />{$Weather[5][1]} ~ {$Weather[11][1]}℃<br>明天：{$Weather[4][1]}<br>{$Weather[6][1]}</div>
EOT;
$s22=<<<EOT
<div class="s1"><img src="{$Weather[3][2]}" width="20" height="20" />{$Weather[5][2]} ~ {$Weather[11][2]}℃<br>后天：{$Weather[4][2]}<br>{$Weather[6][2]}</div>
EOT;
$s23=<<<EOT
<div class="s1"><img src="{$Weather[3][3]}" width="20" height="20" />{$Weather[5][3]} ~ {$Weather[11][3]}℃<br>{$date_3}：{$Weather[4][3]}<br>{$Weather[6][3]}</div>
EOT;
$s24=<<<EOT
<div class="s1"><img src="{$Weather[3][4]}" width="20" height="20" />{$Weather[5][4]} ~ {$Weather[11][4]}℃<br>{$date_4}：{$Weather[4][4]}<br>{$Weather[6][4]}</div>
EOT;
$s25=<<<EOT
<div class="s1"><img src="{$Weather[3][5]}" width="20" height="20" />{$Weather[5][5]} ~ {$Weather[11][3]}℃<br>{$date_5}：{$Weather[4][5]}<br>{$Weather[6][5]}</div>
EOT;
$s26=<<<EOT
<div class="s1"><img src="{$Weather[3][6]}" width="20" height="20" />{$Weather[5][6]} ~ {$Weather[11][6]}℃<br>{$date_6}：{$Weather[4][6]}<br>{$Weather[6][6]}</div>
EOT;

$s30=<<<EOT
<div>今天天气<br>{$Weather[4][0]}<br>{$Weather[6][0]} {$Weather[7][0]}<br>{$Weather[5][0]} ~ {$Weather[11][0]}℃</div>
EOT;
$s31=<<<EOT
<div>明天天气<br>{$Weather[4][1]}<br>{$Weather[6][1]} {$Weather[7][1]}<br>{$Weather[5][1]} ~ {$Weather[11][1]}℃</div>
EOT;
$s32=<<<EOT
<div>后天天气<br>{$Weather[4][2]}<br>{$Weather[6][2]} {$Weather[7][2]}<br>{$Weather[5][2]} ~ {$Weather[11][2]}℃</div>
EOT;
$s33=<<<EOT
<div>{$date_3}天气<br>{$Weather[4][3]}<br>{$Weather[6][3]} {$Weather[7][3]}<br>{$Weather[5][3]} ~ {$Weather[11][3]}℃</div>
EOT;
$s34=<<<EOT
<div>{$date_4}天气<br>{$Weather[4][4]}<br>{$Weather[6][4]} {$Weather[7][4]}<br>{$Weather[5][4]} ~ {$Weather[11][4]}℃</div>
EOT;
$s35=<<<EOT
<div>{$date_5}天气<br>{$Weather[4][5]}<br>{$Weather[6][5]} {$Weather[7][5]}<br>{$Weather[5][5]} ~ {$Weather[11][5]}℃</div>
EOT;
$s36=<<<EOT
<div>{$date_6}天气<br>{$Weather[4][6]}<br>{$Weather[6][6]} {$Weather[7][6]}<br>{$Weather[5][6]} ~ {$Weather[11][6]}℃</div>
EOT;

$s40=<<<EOT
<div>今天天气<br><img src="{$Weather[3][0]}" width="20" height="20" /><img src="{$Weather[9][0]}" width="20" height="20" /><br>{$Weather[4][0]}转{$Weather[10][0]}<br>{$Weather[6][0]} {$Weather[7][0]}<br>{$Weather[5][0]} ~ {$Weather[11][0]}℃</div>
EOT;
$s41=<<<EOT
<div>明天天气<br><img src="{$Weather[3][1]}" width="20" height="20" /><img src="{$Weather[9][1]}" width="20" height="20" /><br>{$Weather[4][1]}转{$Weather[10][1]}<br><br>{$Weather[6][1]} {$Weather[7][1]}<br>{$Weather[5][1]} ~ {$Weather[11][1]}℃</div>
EOT;
$s42=<<<EOT
<div>后天天气<br><img src="{$Weather[3][2]}" width="20" height="20" /><img src="{$Weather[9][2]}" width="20" height="20" /><br>{$Weather[4][2]}转{$Weather[10][2]}<br><br>{$Weather[6][2]} {$Weather[7][2]}<br>{$Weather[5][2]} ~ {$Weather[11][2]}℃</div>
EOT;
$s43=<<<EOT
<div>{$date_3}天气<br><img src="{$Weather[3][3]}" width="20" height="20" /><img src="{$Weather[9][3]}" width="20" height="20" /><br>{$Weather[4][3]}转{$Weather[10][3]}<br><br>{$Weather[6][3]} {$Weather[7][3]}<br>{$Weather[5][3]} ~ {$Weather[11][3]}℃</div>
EOT;
$s44=<<<EOT
<div>{$date_4}天气<br><img src="{$Weather[3][4]}" width="20" height="20" /><img src="{$Weather[9][4]}" width="20" height="20" /><br>{$Weather[4][4]}转{$Weather[10][4]}<br><br>{$Weather[6][4]} {$Weather[7][4]}<br>{$Weather[5][4]} ~ {$Weather[11][4]}℃</div>
EOT;
$s45=<<<EOT
<div>{$date_5}天气<br><img src="{$Weather[3][5]}" width="20" height="20" /><img src="{$Weather[9][5]}" width="20" height="20" /><br>{$Weather[4][5]}转{$Weather[10][5]}<br><br>{$Weather[6][5]} {$Weather[7][5]}<br>{$Weather[5][5]} ~ {$Weather[11][5]}℃</div>
EOT;
$s46=<<<EOT
<div>{$date_6}天气<br><img src="{$Weather[3][6]}" width="20" height="20" /><img src="{$Weather[9][6]}" width="20" height="20" /><br>{$Weather[4][6]}转{$Weather[10][6]}<br><br>{$Weather[6][6]} {$Weather[7][6]}<br>{$Weather[5][6]} ~ {$Weather[11][6]}℃</div>
EOT;

			
print <<<EOT
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>天气预报-天气啦</title>
<style>
table{width:960px; margin-bottom:20px}
textarea{width:100%}
td{width:50%;border:solid 1px}
body{font-size:12px;}
.s1{float:left;text-align:center;margin:0px 5px;font-size:12px;}
</style>
</head><body>
EOT;

switch($_GET['style']){
case 1:
print <<<EOT
<b>{$city['Ab']}</b>  <img src="{$Weather[3][0]}" width="20" height="20" />
$tq {$Weather[5][0]} ~ {$Weather[11][0]}℃   {$Weather[6][0]}{$Weather[7][0]}  <a href="/{$city['pinyin']}.html" target="_blank">详细>></a>
EOT;
break; 
case 21:
print <<<EOT
<div class="s1"><br><b>{$city['Ab']}</b><br></div>
{$s20}{$s21}{$s22}{$s23}{$s24}{$s25}{$s26}
EOT;
break; 
case 22:
print <<<EOT
<div class="s1"><br><b>{$city['Ab']}</b><br></div>
{$s20}{$s21}{$s22}{$s23}{$s24}{$s25}
EOT;
break; 
case 23:
print <<<EOT
<div class="s1"><br><b>{$city['Ab']}</b><br></div>
{$s20}{$s21}{$s22}{$s23}{$s24}
EOT;
break; 
case 24:
print <<<EOT
<div class="s1"><br><b>{$city['Ab']}</b><br></div>
{$s20}{$s21}{$s22}{$s23}
EOT;
break; 
case 25:
print <<<EOT
<div class="s1"><br><b>{$city['Ab']}</b><br></div>
{$s20}{$s21}{$s22}
EOT;
break; 
case 26:
print <<<EOT
<div class="s1"><br><b>{$city['Ab']}</b><br></div>
{$s20}{$s21}
EOT;
break; 
case 27:
print <<<EOT
<div class="s1"><br><b>{$city['Ab']}</b><br></div>
{$s20}
EOT;
break; 
case 31:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s30}</div>
EOT;
break; 
case 32:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s30}{$s31}</div>
EOT;
break; 
case 33:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s30}{$s31}{$s32}</div>
EOT;
break;
case 34:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s30}{$s31}{$s32}{$s33}</div>
EOT;
break;
case 35:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s30}{$s31}{$s32}{$s33}{$s34}</div>
EOT;
break;
case 36:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s30}{$s31}{$s32}{$s33}{$s34}{$s35}</div>
EOT;
break;
case 37:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s30}{$s31}{$s32}{$s33}{$s34}{$s35}{$s36}</div>
EOT;
break;
case 41:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s40}</div>
EOT;
break;
case 42:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s40}{$s41}</div>
EOT;
break;
case 43:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s40}{$s41}{$s42}</div>
EOT;
break;
case 44:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s40}{$s41}{$s42}{$s43}</div>
EOT;
break;
case 45:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s40}{$s41}{$s42}{$s43}{$s44}</div>
EOT;
break;
case 46:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s40}{$s41}{$s42}{$s43}{$s44}{$s45}</div>
EOT;
break;
case 47:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div>{$s40}{$s41}{$s42}{$s43}{$s44}{$s44}{$s46}</div>
EOT;
break;
case 5:
print <<<EOT
<b>{$city['Ab']}</b>  {$Weather[5][0]} ~ {$Weather[11][0]}℃ {$Weather[4][0]}  <a href="/{$city['pinyin']}.html" target="_blank">详细>></a>
EOT;
break; 
case 6:
print <<<EOT
<div style="text-align:center"><div><b>{$city['Ab']}天气预报</b></div><div>今天天气<br><img src="{$Weather[3][0]}" width="20" height="20" /><img src="{$Weather[9][0]}" width="20" height="20" /><br>{$Weather[4][0]}转{$Weather[10][0]}</div></div>
EOT;
break; 
case 7:
$date1=date('Y\年n\月j\日 \星期 N'); 
print <<<EOT
<b>{$city['Ab']}天气</b> {$Weather[4][0]} {$Weather[5][0]} ~ {$Weather[11][0]}℃<br><div><img src="{$Weather[3][0]}" width="40" height="40" style="float:left;" />{$Weather[6][0]} {$Weather[7][0]}<br>{$date1}</div>
EOT;
break; 
case 8:
print <<<EOT
<div><img src="{$Weather[3][0]}" width="40" height="40" style="float:right;" /><b>{$city['Ab']}天气预报</b><br>今天：{$Weather[5][0]} ~ {$Weather[11][0]}℃  {$Weather[4][0]}转{$Weather[10][0]}<br>明天：{$Weather[5][1]} ~ {$Weather[11][1]}℃  {$Weather[4][1]}转{$Weather[10][1]}</div>
EOT;
break;
case 9:
$date_91=date("m").'月'.date("d",strtotime("+0 day")).'日';
$date_92=date("m").'月'.date("d",strtotime("+1 day")).'日';
$date_93=date("m").'月'.date("d",strtotime("+2 day")).'日';
print <<<EOT
<div style="float:left;"><b>{$city['Ab']}天气</b><br><br><a href="http://www.tianqi.la/dy.php" target="_blank">[定制城市]</a></div><div style="float:left;text-align:center"><img src="{$Weather[3][0]}" width="40" height="40" style="float:left;" />今天{$date_91}<br>{$Weather[4][0]}<br>{$Weather[5][0]} ~ {$Weather[11][0]}℃</div><div style="float:left;text-align:center"><img src="{$Weather[3][1]}" width="40" height="40" style="float:left;" />明天{$date_92}<br>{$Weather[4][1]}<br>{$Weather[5][1]} ~ {$Weather[11][1]}℃</div><div style="float:left;text-align:center"><img src="{$Weather[3][2]}" width="40" height="40" style="float:left;" />后天{$date_93}<br>{$Weather[4][2]}<br>{$Weather[5][2]} ~ {$Weather[11][2]}℃</div>
EOT;
break;
case 10:
print <<<EOT
<style>
.wtdate,.wtname,.wtwt,.wttemp{float:left; height:25px; line-height:25px;width:auto }
.wtname{ margin-right:5px;}
.wtwt{ margin-left:5px; }
.wttemp{ margin-left:5px;}
.cls_container{width:400px;font-size:12px;height:24px;overflow:hidden;}
.cls_container ul{list-style-type:none;margin:0;padding:0;}
.cls_container ul li{height:25px;line-height:25px;width:320px;float:left;display:inline;}
</style>
<div id="myscroll" class="cls_container"><ul>
<li><div class="wtdate"><strong>今天：</strong></div><div class="wtname">{$city['Ab']}</div><img src="{$Weather[3][0]}" width="20" height="20" style="float:left" /><div class="wtwt">{$Weather[4][0]}</div><div class="wttemp">{$Weather[5][0]}℃～{$Weather[11][0]}℃ {$Weather[7][0]} <a href="/{$city['pinyin']}.html" target="_blank">详细>></a>&raquo;</div></li>
<li><div class="wtdate"><strong>明天：</strong></div><div class="wtname">{$city['Ab']}</div><img src="{$Weather[3][1]}" width="20" height="20" style="float:left" /><div class="wtwt">{$Weather[4][2]}</div><div class="wttemp">{$Weather[5][1]}℃～{$Weather[11][1]}℃ {$Weather[7][1]} <a href="/{$city['pinyin']}.html" target="_blank">详细>></a>&raquo;</div></li>
<li><div class="wtdate"><strong>后天：</strong></div><div class="wtname">{$city['Ab']}</div><img src="{$Weather[3][2]}" width="20" height="20" style="float:left" /><div class="wtwt">{$Weather[4][3]}</div><div class="wttemp">{$Weather[5][2]}℃～{$Weather[11][2]}℃ {$Weather[7][2]} <a href="/{$city['pinyin']}.html" target="_blank">详细>></a>&raquo;</div></li>
</ul></div></a><div id="showhint"></div>
<script language="JavaScript">
function $(element){
 if(arguments.length>1){
  for(var i=0,length=arguments.length,elements=[];i<length;i++){
   elements.push($(arguments[i]));
  }
  return elements;
 }
 if(typeof element=="string"){
  return document.getElementById(element);
 }else{
  return element;
 }
}
var Class={
 create:function(){
  return function(){
   this.initialize.apply(this,arguments);
  }
 }
}
Function.prototype.bind=function(object){
 var method=this;
 return function(){
  method.apply(object,arguments);
 }
}
var Scroll=Class.create();
Scroll.prototype={
 initialize:function(element,height){
  this.element=$(element);
  this.element.innerHTML+=this.element.innerHTML;
  this.height=height;
  this.maxHeight=this.element.scrollHeight/2;
  this.counter=0;
  this.scroll();
  this.timer="";
  this.element.onmouseover=this.stop.bind(this);
  this.element.onmouseout=function(){this.timer=setTimeout(this.scroll.bind(this),1000);}.bind(this);
 },
 scroll:function(){
  if(this.element.scrollTop<this.maxHeight){
   this.element.scrollTop++;
   this.counter++;
  }else{
   this.element.scrollTop=0;
   this.counter=0;
  }
  
  if(this.counter<this.height){
   this.timer=setTimeout(this.scroll.bind(this),22);
  }else{
   this.counter=0;
   this.timer=setTimeout(this.scroll.bind(this),3126);
  }
 },
 stop:function(){
  clearTimeout(this.timer);
 }
}
var myscroll=new Scroll("myscroll",25);
</script>
EOT;
break;
case 11:
print <<<EOT
<style>
.col_kx { OVERFLOW: hidden; WIDTH:500px;}
#header_demo1{border:0px}
#header_demo2{border:0px}
</style>
<div id="header_demo" class="col_kx"><table border="0" cellspacing="0" cellpadding="0"><a target="_blank" href=""><tr><td id="header_demo1" nowrap>
<strong>今天：</strong>{$city['Ab']} {$Weather[4][0]} <span style='color:#cc3300\">{$Weather[5][0]}℃</span>～<span style='color:#339900\">{$Weather[11][0]}℃</span> {$Weather[7][0]}&nbsp
<strong>明天：</strong>{$city['Ab']} {$Weather[4][1]} <span style='color:#cc3300\">{$Weather[5][1]}℃</span>～<span style='color:#339900\">{$Weather[11][1]}℃</span> {$Weather[7][1]}&nbsp
<strong>后天：</strong>{$city['Ab']} {$Weather[4][2]} <span style='color:#cc3300\">{$Weather[5][2]}℃</span>～<span style='color:#339900\">{$Weather[11][2]}℃</span> {$Weather[7][2]}&nbsp        </td><td id="header_demo2" nowrap></td></tr></a></table></div>
<script language="JavaScript">
    //滚动头条
    //滚动效果
    var header_demo = document.getElementById("header_demo");
    var header_demo1 = document.getElementById("header_demo1");
    var header_demo2 = document.getElementById("header_demo2");
    var speed=20;    //数值越大滚动速度越慢
    header_demo2.innerHTML = header_demo1.innerHTML;

    //header_demo2.offsetWidth 总宽度 
    //alert(header_demo2.offsetWidth +"-"+header_demo.scrollLeft);

    function Marquee(){
    if(header_demo2.offsetWidth-header_demo.scrollLeft<=0)
    header_demo.scrollLeft-=header_demo1.offsetWidth
    else{
    header_demo.scrollLeft++
    }
    }
    var MyMar = setInterval(Marquee,speed);
    header_demo.onmouseover = function(){clearInterval(MyMar)}
    header_demo.onmouseout = function(){MyMar = setInterval(Marquee,speed)}
</script>
EOT;
break; 
}


print <<<EOT
</body></html>
EOT;
?>
